/*
 * @(#)Client.java     Robert Denda&Didier Gutacker
 *
 */

/** 
 * Die Klasse ButtonPanelClient stellt die benoetigten Funktionen fuer die Fernsteuerung
 * der Simulation bereit.
 *
 * @author 	Robert Denda&Didier Gutacker
 * @version     1.1, 05.09.1997
 * @see SimulationClient
 * @see Server
 * @see Connection
 *
 */

import java.net.*;
import java.io.*;

public class Client implements Runnable {

  Connection connection;
  Thread clientThread;

  String eventName;

  public Client( String host, int port ) {
    try {
      Socket socket = new Socket( host, port );
      connection = new Connection( socket );
    } catch( IOException e ) {
    } // try

    clientThread = new Thread( this );
    clientThread.start();
  } // Client.Client

  synchronized public void run() {
    for ( ; ; ) {
      eventName = new String( connection.read() );
      notify();			// handshake
      try {
	wait();
      } catch( InterruptedException e ) {
      } // try
    } // for 
  } // Client.run
    
  synchronized public String getEvent() {
    if ( eventName == null ) {
      try{
	wait();
      } catch( InterruptedException e ) {
      } // try
    } // if
    notify();
    return eventName;
  } // Client.getEvent

} // Client
